package pos.utils;

import java.util.ArrayList;
import java.util.List;

import pos.data.IPuntoDAO;
import pos.data.JDBCPuntoDAO;
import pos.domain.Punto;

public class Autocompletar {
	private int totalCountries;

	/* Empiezo */
	private List<String> countries;

	public Autocompletar() {
		countries = new ArrayList<String>();
		IPuntoDAO ipunto = new JDBCPuntoDAO();
		List<Punto> puntos = ipunto.selectAllPunto();
		for (Punto p : puntos) {
			countries.add(p.getNombre());

		}
		totalCountries = countries.size();
	}

	/* Acabo */

	public List<String> getData(String query) {
		String country = null;
		query = query.toLowerCase();
		List<String> matched = new ArrayList<String>();
		for (int i = 0; i < totalCountries; i++) {
			country = countries.get(i).toLowerCase();
			if (country.startsWith(query)) {
				matched.add(countries.get(i));
			}
		}
		return matched;
	}
}
